package com.gokzzz.controller;

import com.gokzzz.response.Response;
import com.gokzzz.service.EsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * @author ganfujia
 * @date 2022/5/20 9:42
 */
@Api(tags = "es测试")
@RestController
@RequestMapping("/es")
@RequiredArgsConstructor
public class EsController {
    private final EsService esService;


    @PostMapping("/page")
    public Response page(@RequestParam(defaultValue = "1") Long current,
                         @RequestParam(defaultValue = "10")Long size,
                         String q) throws IOException {
        return Response.success().setData(esService.page(current, size,q));
    }

    @ApiOperation("Mysql数据导入ES")
    @GetMapping("/initData")
    public Response initData(){
        esService.initData();
        return Response.success();
    }
}
